import Vue from "vue";
import Router from "vue-router";

Vue.use(Router);

/* Layout */
import Layout from "@/layout";

export const constantRoutes = [
  {
    path: "/login",
    component: () => import("@/views/Login/index"),
    hidden: true,
  },

  {
    path: "/",
    component: Layout,
    redirect: "/dashboard",
    children: [
      {
        path: "dashboard",
        name: "Dashboard",
        component: () => import("@/views/Dashboard/index"),
        meta: { title: "首页", icon: "dashboard" },
      },
    ],
  },
  // 组织架构
  {
    path: "/department",
    component: Layout,
    children: [
      {
        path: "",
        name: "departments",
        component: () => import("@/views/Department/index"),
        meta: { title: "组织架构", icon: "tree" },
      },
    ],
  },
  // 角色管理
  {
    path: "/setting",
    component: Layout,
    children: [
      {
        path: "",
        name: "settings",
        component: () => import("@/views/Setting/index"),
        meta: { title: "角色管理", icon: "setting" },
      },
    ],
  },
  // 员工管理
  {
    path: "/employee",
    component: Layout,
    children: [
      {
        path: "",
        name: "employees",
        component: () => import("@/views/Employee/index"),
        meta: { title: "员工管理", icon: "people" },
      },
    ],
  },

  // 权限点
  {
    path: "/permission",
    component: Layout,
    children: [
      {
        path: "",
        name: "permissions",
        component: () => import("@/views/Permission/index"),
        meta: { title: "权限点管理", icon: "lock" },
      },
    ],
  },

  {
    path: "/salarys",
    component: Layout,
    hidden: false,
    children: [
      {
        path: "", // 如果children path置空的话 当前这个路由会作为一级渲染的默认路由
        name: "salarys",
        component: () => import("@/views/Salary"),
        meta: { title: "工资管理", icon: "money" },
      },
    ],
  },
  {
    path: "/404",
    component: () => import("@/views/404"),
    hidden: false,
  },
];

const createRouter = () =>
  new Router({
    // mode: 'history', // require service support
    mode: "history",
    scrollBehavior: () => ({ y: 0 }),
    routes: constantRoutes,
  });

const router = createRouter();

// reset 路由方法
export function resetRouter() {
  // 得到一个全新的router实例对象
  const newRouter = createRouter();
  // 使用新的路由记录覆盖掉老的路由记录
  router.matcher = newRouter.matcher; // reset router
}

export default router;
